< previous page page_595 next page >

Page 595
9f31265bb40b592b1929e18a47ab28e5.gif
   ' This is the key you wish to set
   strKey = "Software" & _
            "\VB and VBA Program Settings" & _
            "\Invoice\DataSource"

   ' Attempt to open the registry key.
   lngStatus = RegOpenKeyEx(ByVal HKEY_CURRENT_USER, _
                          ByVal strKey, _
                          ByVal 0, _
                          ByVal KEY_ALL_ACCESS, _
                          lngKey)

   If lngStatus = ERROR_SUCCESS Then
      strKey = "DataLoc"
      strValue = txtValue
      lngStatus = RegSetValueEx(ByVal lngKey, _
                              ByVal strKey, _
                              ByVal 0, _
                              ByVal REG_SZ, _
                              ByVal strValue, _
                              Len(strValue)) 
      If lngStatus <> ERROR_SUCCESS Then
         txtValue = "Error Setting Value"
      End If
   Else
      MsgBox "Error Opening Key"
   End If
   ' Close the Key
   lngStatus = RegCloseKey(lngKey)
End Sub
Saving information to the Registry is almost exactly the same as retrieving information from the Registry. You need to open a key, get a handle, and then use that handle with the RegSetValueEX() function. When youre done, you need to close the key so that resources are released.

 
< previous page page_595 next page >

If you like this book, buy it!